package com.webside.points.wechat;
import java.io.ByteArrayInputStream;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;




public class Util {

	public static InputStream getStringStream(String sInputString) {
        ByteArrayInputStream tInputStringStream = null;
        if (sInputString != null && !sInputString.trim().equals("")) {
            tInputStringStream = new ByteArrayInputStream(sInputString.getBytes());
        }
        return tInputStringStream;
    }
	
	public static String amountTurnCent(String amount){
		if(amount!=""&&amount!=null){
			int money=0;
			money=(int) (Double.valueOf(amount)*100);
			return String.valueOf(money);
		}
		return "0";
	}
	
	public static Double centTurnAmount(String amount){
		if(amount!=""&&amount!=null){
			Double money=0.0;
			money=(Double) (Double.valueOf(amount)/100);
			return Double.valueOf(money);
		}
		return 0.0;
	}
	
	public static String monthToEnglish(String month){	
		if(month!=null){
			if(month.equals("01")){
				return "Jan";
			}else if(month.equals("02")){
				return "Feb";
			}else if(month.equals("03")){
				return "Mar";
			}else if(month.equals("04")){
				return "Apr";
			}else if(month.equals("05")){
				return "May";
			}else if(month.equals("06")){
				return "Jun";
			}else if(month.equals("07")){
				return "Jul";
			}else if(month.equals("08")){
				return "Aug";
			}else if(month.equals("09")){
				return "Sep";
			}else if(month.equals("10")){
				return "Oct";
			}else if(month.equals("11")){
				return "Nov";
			}else if(month.equals("12")){
				return "Dec";
			}
		}
		return null;
	}
	// 加密  
    public static String getBase64(String str) {  
        byte[] b = null;  
        String s = null;  
        try {  
            b = str.getBytes("utf-8");  
        } catch (UnsupportedEncodingException e) {  
            e.printStackTrace();  
        }  
        if (b != null) {  
            s = new BASE64Encoder().encode(b);  
        }  
        return s;  
    }  
  
    // 解密  
    public static String getFromBase64(String s) {  
        byte[] b = null;  
        String result = null;  
        if (s != null) {  
            BASE64Decoder decoder = new BASE64Decoder();  
            try {  
                b = decoder.decodeBuffer(s);  
                result = new String(b, "utf-8");  
            } catch (Exception e) {  
                e.printStackTrace();  
            }  
        }  
        return result;  
    }
}

